/*
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

#ifndef _POINTTOOLTIP_H
#define _POINTTOOLTIP_H

#include <cmath>

#include <QToolTip>
#include <QPoint>
#include <QPointF>
#include <QString>
#include <QTextStream>
#include <QListView>
#include <QStringListModel>
#include <QFocusEvent>
#include <QStyledItemDelegate>
#include <QTextDocument>
#include <QPainter>
#include <QDialog>
#include <QVBoxLayout>
#include <QBrush>
#include <QColor>

#include "../gType.h"

#define COLOR_TAG 			"red"
#define COLOR_COORDINATES	"blue"
#define COLOR_MIDDLE		"green"
#define COLOR_PARAMS		"gray"
#define COLOR_VALUE			"black"



class pointToolTip: public QToolTip{

	private:
		static const int FLOAT_PRECISION = 3;
		

	public:
		static void setStream(QTextStream &, gObject *, gTypeGo *);
		static void showGInformation(const QPoint &, gObject *, gTypeGo *, QWidget *);
		static void showGInformations(const QPoint &, gObjectContainer *, QWidget *);
		static void showDistance(const QPoint &, const QPointF &, const QPointF &, const QPointF &, QWidget *);

};

class HTMLDelegate;

class listToolTip: public QListView{

	Q_OBJECT
	
	private:
		class additional{
			public:
				gTypeGo *go;
				int i;
		};
		
		QStringListModel *model;
		QList<additional> *modelAdd;
		HTMLDelegate *delegate;
		bool shift;
		
		void appendGTypeGo(gObject &, gTypeGo &, QStringList &) const;
				
	protected:
		virtual void mouseDoubleClickEvent(QMouseEvent *);
		
	signals:
		void doubleClicked(int, gTypeGo *);
		void clicked(int, gTypeGo *);
	
	public:
		listToolTip(QWidget * = 0);
		~listToolTip();
		
		void setObject(gObjectContainer *, gObject *, gObject *);
		void setContainer(gObjectContainer *);
		void show(const QPoint &);
		int gTypeCount() const;
	
};

class HTMLDelegate: public QStyledItemDelegate{
	
	protected:
		void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const;
		QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
		
};

class listToolTipDialog: public QDialog{

	Q_OBJECT
	
	public:
		enum states{NONE, CLICKED, DOUBLECLICKED};
	
	private:
		states state;
		
		int object;
		gTypeGo *go;
		
		listToolTip *listTip;
		QVBoxLayout *vLayout;
		
	
	private slots:
		void clicked(int, gTypeGo *);
		void doubleClicked(int, gTypeGo *);
		
	public:
		listToolTipDialog(QWidget * = 0);
		
		void setObject(gObjectContainer *container, gObject *object, gObject *objectPointer)
			{ listTip->setObject(container, object, objectPointer); state = NONE; };
		void setContainer(gObjectContainer *container)
			{ listTip->setContainer(container); state = NONE; };
		
		int count() const{ return listTip->gTypeCount(); };
		int getGObject() const{ return object; };
		gTypeGo *getGTypeGo() const{ return go; };
		states getState() const{ return state; };

};

#endif
